﻿using System;

namespace Test30.Core
{
    public static class Int32Extensions
    {
        public static int Clamp(this int value, int min, int max)
        {
            if (min > max) throw new ArgumentOutOfRangeException($"min必须小于等于max.");
            return Math.Max(min, Math.Min(max, value));
        }

        public static float Normalize(this int value, float min, float max)
        {
            return ((float)value).Normalize(min, max);
        }

        public static int Remap(this int value, int min, int max, int outMin, int outMax)
        {
            if (min == max) throw new ArgumentOutOfRangeException($"min和max不能相等.");
            return (int)(((float)value).Normalize(min, max) * (outMax - outMin)) + outMin;
        }

        public static float Remap(this int value, int min, int max, float outMin, float outMax)
        {
            if (min == max) throw new ArgumentOutOfRangeException($"min和max不能相等.");
            return (((float)value).Normalize(min, max) * (outMax - outMin)) + outMin;
        }
    }
}
